// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "WorldEntityManager.h"

/**
 * Helper to chain referencings.
 */
class FWorldEntityReferencing
{

public:

	FWorldEntityReferencing(FWorldEntityManager* em)
		: _em(em)
	{}

	template<typename OtherType>
	FWorldEntityReferencing& Resolve(FWorldEntityReference<OtherType>& prop)
	{
		_em->Resolve<OtherType, OtherType>(prop);
		return *this;
	}

	template<typename OtherType, typename ParentType>
	FWorldEntityReferencing& Resolve(FWorldEntityReference<ParentType>& prop)
	{
		_em->Resolve<OtherType, ParentType>(prop);
		return *this;
	}

	template<typename OtherType>
	FWorldEntityReferencing& Resolve(FWorldEntityArrayReference<OtherType>& prop)
	{
		_em->ResolveOneToMany(prop);
		return *this;
	}

	template<typename OtherType, int MinOccurance>
	FWorldEntityReferencing& Resolve(FWorldEntityPartReference<OtherType, MinOccurance>& part)
	{
		if (part) part->Resolve(*this);
		return *this;
	}

	template<typename OtherType, int MinOccurance, int MaxOccurance>
	FWorldEntityReferencing& Resolve(FWorldEntityPartArrayReference<OtherType, MinOccurance, MaxOccurance>& parts)
	{
		for (auto& part : parts)
		{
			if (part) part->Resolve(*this);
		}
		return *this;
	}

private:

	FWorldEntityManager* _em;

};
